package jjn.acwing.algorithm_basic.chapter1.binary_search;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author Jiang Jining
 * @since 2023-09-16 21:16
 */
public class Acwing789 {
    
    static void binarySearch(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        // search for first num <= target
        while (l < r) {
            int mid = (l + r) / 2;
            if (nums[mid] >= target) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        if (nums[l] != target) {
            System.out.println("-1 -1");
        } else {
            System.out.printf("%d ", l);
            l = 0;
            r = nums.length - 1;
            // search for first num >= target
            while (l < r) {
                int mid = (l + r + 1) / 2;
                if (nums[mid] <= target) {
                    l = mid;
                } else {
                    r = mid - 1;
                }
            }
            System.out.printf("%d\n", nums[l]);
        }
        
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String line = bufferedReader.readLine();
        String[] parts = line.split(" ");
        int n = Integer.parseInt(parts[0]), q = Integer.parseInt(parts[1]);
        int[] nums = new int[n];
        String number = bufferedReader.readLine();
        String[] strings = number.split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(strings[i]);
        }
        int[] k = new int[q];
        for (int i = 0; i < q; i++) {
            String read = bufferedReader.readLine();
            k[i] = Integer.parseInt(read);
        }
        for (int num : k) {
            binarySearch(nums, num);
        }
    }
}
